﻿Public Class clsCPLHCK
    Public Function getListByProdId(prodid As String) As DataTable
        Dim szSql As String = ""
        szSql &= "select * from sf.b_lh_ck where 1 = 1 and prod_id = '" + prodid + "'"
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

    Public Function intoCK(en As entity_cplh_ck) As Integer
        Dim sql As String = ""
        Dim rtn As Integer = 0
        DBacs.BeginTransaction()
        Try
            sql &= "INSERT INTO sf.b_lh_ck( factory_id, wh_no, prod_id, b_pgd_mes_sys_id ,into_time, status, into_ope, update_time)  "
            sql &= "VALUES ( ?, ?, ?, ?, (SELECT CURRENT_TIMESTAMP(6)), ?, ?, (SELECT CURRENT_TIMESTAMP(6)))"
            With en
                rtn = DBacs.ExecuteUpdateSql(sql, -1， .factory_id, .wh_no, .prod_id, .b_pgd_mes_sys_id, .status, .into_ope)
            End With
            sql = "select * from sf.b_pgd_nc where 1 = 1 and b_pgd_mes_sys_id = ? and procedure_name = ? "
            Dim dt As DataTable = DBacs.ExecuteSql(sql, -1, en.b_pgd_mes_sys_id, "硫化")
            If dt.Rows.Count > 0 Then
                sql = "INSERT INTO sf.b_pgd_nc_workreport(b_pgd_mes_sys_id, b_pgd_mes_details_sys_id, oper_date, mes_project_code, mes_project_name, prod_spec_id, prod_spec_name, oper_count, procedure_name,warehouse, create_time,prod_id) "
                sql &= "VALUES ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , (SELECT CURRENT_TIMESTAMP(6)),?); "
                rtn = DBacs.ExecuteUpdateSql(sql, -1, en.b_pgd_mes_sys_id, dt.Rows(0)("b_pgd_mes_details_sys_id"), dt.Rows(0)("oper_date"), dt.Rows(0)("mes_project_code"),
                                             dt.Rows(0)("mes_project_name"), dt.Rows(0)("prod_spec_id"), dt.Rows(0)("prod_spec_name"),
                                             "1", dt.Rows(0)("procedure_name"), "隔震硫化库", en.prod_id)
            End If
            sql = "update sf.b_prod_info set update_time = (SELECT CURRENT_TIMESTAMP(6)), status = ? "
            sql &= " where factory_id = ? and prod_id = ?"
            rtn = DBacs.ExecuteUpdateSql(sql, -1, "9", "TS", en.prod_id)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

End Class
